package subject_set.top101;

/**
 * @author haomin
 * @date 2022/11/02 22:18
 **/
public class BM39 {
    public class Solution {
        String Serialize(TreeNode root) {
            StringBuffer sb = new StringBuffer();
            if(root == null) return "&,";
            sb.append(root.val).append(",");
            sb.append(Serialize(root.left));
            sb.append(Serialize(root.right));
            return sb.toString();
        }
        TreeNode Deserialize(String str) {
            String[] s = str.split(",");
            return createTree(s);
        }
        int post = -1;
        private TreeNode createTree(String[] s){
            post++;
            if(s[post].equals("&")) return null;
            TreeNode cur = new TreeNode(Integer.parseInt(s[post]));
            cur.left = createTree(s);
            cur.right = createTree(s);
            return cur;
        }
    }
}